package com.fsnbigdata.repository;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt;
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryCustomImpl;
import com.fsnbigdata.domain.ListQuadratItem;
import com.fsnbigdata.domain.ListQuadrat;
import com.fsnbigdata.domain.QListQuadratItem;
import com.querydsl.core.types.Path;
import com.querydsl.jpa.JPQLQuery;
import io.springlets.data.domain.GlobalSearch;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt.AttributeMappingBuilder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * = ListQuadratItemRepositoryImpl
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJpaRepositoryCustomImpl(repository = ListQuadratItemRepositoryCustom.class)
@Transactional(readOnly = true)
public class ListQuadratItemRepositoryImpl extends QueryDslRepositorySupportExt<ListQuadratItem> implements ListQuadratItemRepositoryCustom {

    /**
     * TODO Auto-generated constructor documentation
     */
    ListQuadratItemRepositoryImpl() {
        super(ListQuadratItem.class);
    }

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String DBH_MAX = "dbhMax";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ORGANISM_ID = "organismId";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String COVERAGE = "coverage";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String HEIGHT_AVG = "heightAvg";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String LATIN = "latin";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CANOPY_AVG = "canopyAvg";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String NAME = "name";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String BIOTYPE = "biotype";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String FLOURISH = "flourish";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String DBH_AVG = "dbhAvg";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ITEMLEVEL = "itemlevel";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String TREE = "tree";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CANOPY_MAX = "canopyMax";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String LIST_QUADRAT = "listQuadrat";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String HEIGHT_MAX = "heightMax";

    /**
     * TODO Auto-generated method documentation
     *
     * @param listQuadrat
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    public Page<ListQuadratItem> findByListQuadrat(ListQuadrat listQuadrat, GlobalSearch globalSearch, Pageable pageable) {
        QListQuadratItem listQuadratItem = QListQuadratItem.listQuadratItem;
        JPQLQuery<ListQuadratItem> query = from(listQuadratItem);
        Assert.notNull(listQuadrat, "listQuadrat is required");
        query.where(listQuadratItem.listQuadrat.eq(listQuadrat));
        Path<?>[] paths = new Path<?>[] { listQuadratItem.listQuadrat, listQuadratItem.name, listQuadratItem.latin, listQuadratItem.organismId, listQuadratItem.itemlevel, listQuadratItem.tree, listQuadratItem.coverage, listQuadratItem.heightAvg, listQuadratItem.heightMax, listQuadratItem.dbhAvg, listQuadratItem.dbhMax, listQuadratItem.canopyAvg, listQuadratItem.canopyMax, listQuadratItem.flourish, listQuadratItem.biotype };
        applyGlobalSearch(globalSearch, query, paths);
        AttributeMappingBuilder mapping = buildMapper().map(LIST_QUADRAT, listQuadratItem.listQuadrat).map(NAME, listQuadratItem.name).map(LATIN, listQuadratItem.latin).map(ORGANISM_ID, listQuadratItem.organismId).map(ITEMLEVEL, listQuadratItem.itemlevel).map(TREE, listQuadratItem.tree).map(COVERAGE, listQuadratItem.coverage).map(HEIGHT_AVG, listQuadratItem.heightAvg).map(HEIGHT_MAX, listQuadratItem.heightMax).map(DBH_AVG, listQuadratItem.dbhAvg).map(DBH_MAX, listQuadratItem.dbhMax).map(CANOPY_AVG, listQuadratItem.canopyAvg).map(CANOPY_MAX, listQuadratItem.canopyMax).map(FLOURISH, listQuadratItem.flourish).map(BIOTYPE, listQuadratItem.biotype);
        applyPagination(pageable, query, mapping);
        applyOrderById(query);
        return loadPage(query, pageable, listQuadratItem);
    }
}
